package com.gelsanalyzer.business;

// Generated Feb 24, 2008 6:39:14 PM by Hibernate Tools 3.2.0.CR1

import static org.hibernate.criterion.Example.create;

import java.util.*;

import org.apache.commons.logging.*;
import org.hibernate.*;

import com.gelsanalyzer.core.*;

/**
 * Home object for domain model class MapCourseGoalarea.
 * @see com.gelsanalyzer.business.MapCourseGoalarea
 * @author Hibernate Tools
 */
public class MapCourseGoalareaHome {

    private static final Log log = LogFactory
        .getLog(MapCourseGoalareaHome.class);

    private final SessionFactory sessionFactory = HibernateUtil
        .getSessionFactory();

    public void persist(MapCourseGoalarea transientInstance) {
        log.debug("persisting MapCourseGoalarea instance");
        try {
            Session session = sessionFactory.getCurrentSession();
            session.beginTransaction();

            session.persist(transientInstance);

            session.getTransaction().commit();

            log.debug("persist successful");
        } catch ( RuntimeException re ) {
            log.error("persist failed", re);
            throw re;
        }
    }

    public void attachDirty(MapCourseGoalarea instance) {
        log.debug("attaching dirty MapCourseGoalarea instance");
        try {
            Session session = sessionFactory.getCurrentSession();
            session.beginTransaction();

            session.saveOrUpdate(instance);

            session.getTransaction().commit();

            log.debug("attach successful");
        } catch ( RuntimeException re ) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void attachClean(MapCourseGoalarea instance) {
        log.debug("attaching clean MapCourseGoalarea instance");
        try {
            Session session = sessionFactory.getCurrentSession();
            session.beginTransaction();

            session.lock(instance, LockMode.NONE);

            session.getTransaction().commit();

            log.debug("attach successful");
        } catch ( RuntimeException re ) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void delete(MapCourseGoalarea persistentInstance) {
        log.debug("deleting MapCourseGoalarea instance");
        try {
            Session session = sessionFactory.getCurrentSession();
            session.beginTransaction();

            session.delete(persistentInstance);

            session.getTransaction().commit();

            log.debug("delete successful");
        } catch ( RuntimeException re ) {
            log.error("delete failed", re);
            throw re;
        }
    }

    public MapCourseGoalarea merge(MapCourseGoalarea detachedInstance) {
        log.debug("merging MapCourseGoalarea instance");
        try {
            Session session = sessionFactory.getCurrentSession();
            session.beginTransaction();

            MapCourseGoalarea result = (MapCourseGoalarea) session
                .merge(detachedInstance);

            session.getTransaction().commit();

            log.debug("merge successful");
            return result;
        } catch ( RuntimeException re ) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public MapCourseGoalarea findById(int id) {
        log.debug("getting MapCourseGoalarea instance with id: " + id);
        try {
            Session session = sessionFactory.getCurrentSession();
            session.beginTransaction();

            MapCourseGoalarea instance = (MapCourseGoalarea) session.get(
                "com.gelsanalyzer.business.MapCourseGoalarea", id);
            if ( instance == null ) {
                log.debug("get successful, no instance found");
            } else {
                log.debug("get successful, instance found");
            }

            session.getTransaction().commit();

            return instance;
        } catch ( RuntimeException re ) {
            log.error("get failed", re);
            throw re;
        }
    }

    public List<MapCourseGoalarea> findByExample(MapCourseGoalarea instance) {
        log.debug("finding MapCourseGoalarea instance by example");
        try {
            Session session = sessionFactory.getCurrentSession();
            session.beginTransaction();

            List<MapCourseGoalarea> results = (List<MapCourseGoalarea>) session
                .createCriteria("com.gelsanalyzer.business.MapCourseGoalarea")
                .add(create(instance)).list();
            log.debug("find by example successful, result size: "
                    + results.size());

            session.getTransaction().commit();

            return results;
        } catch ( RuntimeException re ) {
            log.error("find by example failed", re);
            throw re;
        }
    }

//    public List<MapCourseGoalarea> findByCourse(Course instance) {
//        log.debug("finding MapCourseGoalarea instances by Course");
//        try {
//            Session session = sessionFactory.getCurrentSession();
//            session.beginTransaction();
//            
//            List<MapCourseGoalarea> results = (List<MapCourseGoalarea>) session.createCriteria("com.gelsanalyzer.business.MapCourseGoalarea").add(create(instance)).list();
//            
//            log.debug("find by example successful, result size: "            
//                + results.size());
//        
//            session.getTransaction().commit();
//        
//            return results;
//        }catch  ( RuntimeException re ) {
//            log.error("find by example failed", re);
//            throw re;
//        }
//    }
}
